<template>
  <div class='staffCard' >
      <el-row class='first-title'>
        <div class="lf">
          <h3 class="">员工名片<small class="sub-title">{{searchDeptCategory}}</small></h3>
        </div>
        <search-box @getValue="getSearchText" :text="text"></search-box>
      </el-row>
      <el-row class="second-sec">
        <div class="display-title">
          <div class="rt select-dept">
              <span>请选择部门：</span>
              <el-select  v-model="leaderSec" @change="getLeaderSecList" placeholder="请选择">
                <el-option
                v-for="item in unitList"
                :key="item.deptid"
                :label="item.descr"
                :value="item.descr">
                </el-option>
              </el-select>
          </div> 
        </div>
      </el-row>
      <el-row class="third-card">
        <div class="totalNum">
            &nbsp;
            <div class="rt">共计<strong>{{totalNum}}</strong>人</div>
        </div>
        <div class="containerCard"  v-show="showCard">
          <div class="unitContainer" v-bind:style="{borderTopColor : 'blue'}" >
              <transition name="slide-fade">
                <div class="card-body">
                  <card-leader v-for='item in cardList' :personInfo='item'></card-leader>
                </div>
              </transition>
          </div>
        </div>
      </el-row>
  </div>
</template>

<script>
  import Vue from 'vue'
  import { ButtonGroup,Switch,Select,Input, Col, Row, Radio,RadioGroup,RadioButton,Option, Table,TableColumn,Form,FormItem,Pagination} from 'element-ui' 
  Vue.use(ButtonGroup)
  Vue.use(Switch)
  Vue.use(Select)
  Vue.use(Input)
  Vue.use(Col)
  Vue.use(Row)
  Vue.use(Radio)
  Vue.use(RadioGroup)
  Vue.use(RadioButton)
  Vue.use(Option)
  Vue.use(Table)
  Vue.use(TableColumn)
  Vue.use(Form)
  Vue.use(FormItem)
  Vue.use(Pagination)
  import cardLeader from '@/components/public/card-memeber'
  import searchBox from '@/components/public/search-box'
  import searchCol from '@/components/public/selectShowCol'
    export default {
      data() {
        return {
          value1:null,
          value2:null,
          value3:null,
          radio3:'员工名片',
          unitList: [],
          leaderSec: '',
          loading:false,
          text:'请输入姓名、员工编号搜索',
          searchRecord:null,
          searchText:'',
          searchDeptCategory:'',
          deptDescr:null,
          isLoadEnd:false,
          checkedCities:[0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
          colShow:false,
          cardList:[],
          showCard:true,
          totalNum:null,
          showTable:false,
          tablefit:true,
          englishTitle:null,
          title:null,
          tableOption:null,
          colTotalList:null,
          currentPage:1,
          pageSizeTable:10,
          totalTableNum:null,
          unitTableList:null,
          cardPageSize:30,
          cardPageNum:1,
        }
      },
      methods: {
        handle:function(scope){
          var emplid= scope.row.emplid;
          this.$router.push('/resume?emplid='+emplid);
        },
        targetLeaderRoute:function(scope){
          var emplid= scope.row.emplid;
          window.open( "/module/resume.html?emplid="+emplid);
        },
        clearData:function(){
            this.cardList = [];
            this.unitTableList = [];
            this.cardPageNum = 1;
            this.currentPage = 1;
            
            this.isLoadEnd = false;
        },
        selectAjax:function(){
            if (this.radio3 ==="员工名片") {
                if (this.searchRecord) {
                    var params = {
                        search:this.searchText,
                        pageSize:40,
                        pageNum:this.cardPageNum
                    }
                    this.PostAjax(this.URL.employeeSearch.url,params,3);    
                } else {
                    this.getLeaderListCommonAjax()
                }
            } 
        },
        getSearchText:function(text){
          var self =this;
          this.clearData();
          
          if (!text.trim()) {
              this.clearData();
              this.searchRecord = false;
              this.selectAjax();
              return;
          }
          this.searchText = text;
          this.cardPageNum = 1;
          this.searchRecord = true;
          this.selectAjax();
        },
        handleRowClass:function(row, index){
          return index%2 === 0 ? 'even-row' : 'odd-row';
        },
        dataNeedFunc:function(prop){
         
            return prop === "service_dt" || prop === "birtc_cur_job_dthdate" || prop === "birthdate" || prop === "start_dt_chn";
        },
        concatStr:function(data){
            let ret = ''
            for (let it in data) {
                ret += it + '=' + data[it] + '&'
            }
            return ret;
        },
        assignTitles:function(){
          var title='',englishTitle='';
	    		if (this.tableOption[0].prop !== "num") {
	      		 title += "序号";
	      	}
          for (var j=0;j<this.tableOption.length;j++){
            title = title ?  title + ',' + this.tableOption[j].label : title + this.tableOption[j].label;
            if (this.tableOption[j].prop !== "num") {
                englishTitle = englishTitle ? englishTitle = englishTitle + ',' + this.tableOption[j].prop : englishTitle + this.tableOption[j].prop;
            }
          }
          this.title = title;
          this.englishTitle = englishTitle;
        },
        getLeaderSecList:function(value){
          var self =this;
          this.searchRecord = false;
          if (value === "全部") {
            this.clearData();
            value="";
          }
          this.clearData();
          this.leaderSec = value;
          var type;
          if (value) { type="1";}   

          this.getLeaderListCommonAjax(type);
        },
        
        
    		PostAjax:function(url,params,type){
            var self = this;

            this.Axios.Post(url,params).then(function(res){
            	

                self.totalNum = (res.data.page && res.data.page.total ) ||  res.data.total || 0;
                if (self.searchRecord) {
                		
                		var arr1 = JSON.parse(JSON.stringify(res.data.datas.emplist));
                		self.cardList = self.cardList.concat(arr1);
                    if (self.cardList.length === self.totalNum) {
                        self.isLoadEnd = true;
                    }
//                  self.cardList = arr1;
                } else {
                	
	            		  //获取部门列表
										var arr = res.data.datas.deptlist;
				            arr && arr.unshift({"descr":"全部","total":1,"deptid":""})
				            self.unitList = arr;
				            
				            //获取人员列表

		
		                var arr1 = JSON.parse(JSON.stringify(res.data.datas.emplist));
                	
                	
                    self.cardList = self.cardList.concat(arr1);
                    if (self.cardList.length === self.totalNum) {
                        self.isLoadEnd = true;
                    }
                }
               
                   
                          
            })
        },
        
        
        getLeaderListCommonAjax:function(type){
            var self = this;
            var params = type === 2 ?            
                {
                  employeeId:"",
                  deptCategory:'',
                  deptDescr:this.leaderSec,
                  name:this.searchText,
                  pageSize:this.pageSizeTable ,
                  pageNum:this.currentPage
                }
                :
                {
                  employeeId:"",
                  deptCategory:'',
                  deptDescr:this.leaderSec,
                  name:this.searchText,
                  pageSize:this.cardPageSize,
                  pageNum:this.cardPageNum
                }; 
            this.PostAjax(this.URL.getEmpListByService.url,params,type);
        },

        scrollFunc:function(event) {
            var self = this;
            if (this.isLoadEnd) {
                return;
            }
            var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; 
            if(document.documentElement.scrollHeight - (document.documentElement.clientHeight + scrollTop) == 0 ) {
                self.cardPageNum++;
                self.selectAjax();
            }    
        }
      },
      computed:{
      },
      created:function(){
          var self = this;
          self.colTotalList = [
            {label:'序号',prop:"num",isShow:true,width:'',needAtag:false},
            {label:'单位',prop:"business_descr",isShow:true,width:'',needAtag:false},
            {label:'ID',prop:"emplid",isShow:true,notChecked:true,width:'',needAtag:false},
            {label:'姓名',prop:"name",isShow:true,handle:true,needAtag:true},
            {label:'性别',prop:"sex_descr",isShow:true,class:'width40'},
            {label:'部门',prop:"dept_descr",isShow:true},
            {label:'职务',prop:"c_current_job",isShow:true},
            {label:'入职时间',prop:"service_dt",isShow:true,class:'width90',handle:true},
            {label:'任现职时间',prop:"c_cur_job_dt",isShow:true,class:'width90',handle:true},
            {label:'出生年月',prop:"birthdate",isShow:true,class:'width90',handle:true},
            {label:'政治面貌',prop:"political_sta_chn",isShow:true},
            {label:'参加工作时间',prop:"start_dt_chn",isShow:true,class:'width90',handle:true},
            {label:'最高学历',prop:"highest_edu",isShow:true},
            {label:'最高学位',prop:"highest_deg",isShow:true},
            {label:'毕业院校',prop:"school_descr",isShow:true},
            {label:'所学专业',prop:"major_descr",isShow:true}
          ];
          self.tableOption = JSON.parse(JSON.stringify(self.colTotalList));
          self.assignTitles();
      },
      mounted: function () {
        var self = this;
        this.searchDeptCategory = this.$route.query.q;

        this.getLeaderListCommonAjax();
//      this.Axios.Post(this.URL.getDeptListByType.url,params).then(function(res){
//          var arr = res.data.datas;
//          arr && arr.unshift({"descr":"全部","total":1,"deptid":""})
//          self.unitList = res.data.datas;
//      })
        window.addEventListener("scroll",this.scrollFunc);
      },
      beforeDestroy: function () {
        window.removeEventListener("scroll",this.scrollFunc);
      },
      components: {
        cardLeader,
        searchBox,
        searchCol
      },
      watch:{
        $route:{
          handler : function(val, oldVal){
            this.searchDeptCategory = this.$route.query.q;
            var self = this;
            this.searchText = '';
            this.leaderSec = '';
            this.radio3 = '员工名片';
            this.clearData();
            this.cardPageSize = 30;
            this.cardPageNum = 1;
            this.currentPage = 1;
            this.pageSizeTable = 10;
            this.cardList = [];
            this.unitTableList = null;
            var params={
              employeeId:"",
              deptCategory:this.searchDeptCategory,
              deptDescr:this.leaderSec,
              name:this.searchText
            };
            this.getLeaderListCommonAjax();
            this.Axios.Post(this.URL.getDeptListByType.url,params).then(function(res){
                console.log(res,"unitList")
                var arr = res.data.datas;
                arr.unshift({"descr":"全部","total":1,"deptid":""})
                self.unitList = res.data.datas;
            })
          }
        }
      },
      filters:{
      }
    }
</script>

<style scoped> 
      .staffCard .first-title h3{
          font-size: 24px;
          margin-top: 20px;
          margin-bottom: 20px;
          font-weight: 500;
          line-height: 1.1;
      }
     .staffCard .first-title h3 small{
        font-size: 65%;
        font-weight: normal;
        line-height: 1;
        color: #777;
        margin-left:5px;
      }
      .staffCard .second-sec{
          position: relative;
          border-radius: 3px;
          background: #ffffff;
          border-top: 3px solid #d2d6de;
          margin-bottom: 20px;
          width: 100%;
          box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
          border-top-color: #00a65a;
      }
      .content-right{
        float:right;
        margin-top:17px;
      }
      .staffCard .resumePeo{
        color:#00acd6;
        cursor: pointer;
      }
      .staffCard .select-dept{
        font-size: 14px;
      }
      .staffCard .display-title{
        border-bottom: 1px solid #f4f4f4;
        padding:10px;
        overflow: hidden;
      }
      .staffCard .switch-btn{
        padding: 10px 10px;
      }
      .staffCard .collapse-card{
        position:relative;
        padding: 10px 10px;
        border-bottom: 1px solid #f4f4f4;
      }

      .staffCard .table-container{
          position: relative;
          border-radius: 3px;
          background: #ffffff;
          border-top: 3px solid #d2d6de;
          margin-bottom: 20px;
          width: 100%;
          box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
          border-top-color: #00a65a;
          background-color:#fff;
      }
      .staffCard .unitContainer{
          position: relative;
          border-radius: 3px;
          background: #ffffff;
          border-top: 3px solid #3c8dbc;
          margin-bottom: 20px;
          width: 100%;
          box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
          overflow: hidden;
          clear: both;
      }
      .staffCard .third-card .collapse-card .box-title{
          display: inline-block;
          font-size: 18px;
          color: #444;
          font-weight: 500;
          margin: 0;
          line-height: 1;
      }
      .staffCard .third-card .collapse-card .collapse-container {
          position: absolute;
          right: 10px;
          top: 10px;
          cursor:pointer;
      }
      .staffCard .third-card .collapse-card  .collapse {
          border-radius: 3px;
          -webkit-box-shadow: none;
          box-shadow: none;
          border: 0px;
          padding: 5px;
          font-size: 12px;
          background: transparent;
          color: #97a0b3;
      }
      .totalNum{
          font-size: 14px;
          line-height: 1.42857143;
          color: #333;
      }


    .demo-table-expand {
      font-size: 0;
    }
    .demo-table-expand label {
      width: 90px;
      color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
      margin-right: 0;
      margin-bottom: 0;
      width: 100%;
    }



  /*选项icon样式*/
    .staffCard .handle-table{
      /*overflow: hidden;*/
      clear: both;
      padding:20px 20px 30px 20px;
      border-bottom: 1px solid #dfe6ec;
    }
    .staffCard .selectSet{
      font-size: 14px;
      font-weight: normal;
      line-height: 1.42857143;
      text-align: center;
      white-space: nowrap;
      clear: both;
      position: relative;
    }
    .staffCard .selectSet .default{
      float: left;
      background-color: #f4f4f4;
      color: #444;
      padding: 6px 12px;
      border: 1px solid #ddd;
      border-radius: 3px;
      position: relative;
      z-index:1;
    }
    .staffCard .selectSet .alt{
        margin-right:-1px;
        
    }
    .staffCard .selectSet a:hover{
      z-index:4;  
      color: #333;
      background-color: #e6e6e6;
      border-color: #adadad;
    }
    .staffCard .selectSet .alt{
        margin-right:-1px;
    }

    .selectSet .default:first-child:not(:last-child){
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        
    }
    .selectSet .default:last-child:not(:first-child) {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }

    .staffCard .downloadTable{
      padding: 7px 12px;
      margin-bottom: 0;
      font-size: 14px;
      font-weight: normal;
      line-height: 1.42857143;
      text-align: center;
      white-space: nowrap;
      background-color: #00acd6;
      border-color: #269abc;
      color: #fff;
      border-radius: 3px;
      display:inline-block;
    }
    .staffCard .downloadTable:hover{
      background-color: #3c8dbc;
      border-color: #00acd6;
    }
    
    .caret {
      display: inline-block;
      width: 0;
      height: 0;
      margin-left: 2px;
      vertical-align: middle;
      border-top: 4px dashed;
      border-top: 4px solid \9;
      border-right: 4px solid transparent;
      border-left: 4px solid transparent;
  }



    /* 可以设置不同的进入和离开动画 */
  /* 设置持续时间和动画函数 */
  .slide-fade-enter-active {
    transition: all .2s ease;
  }
  .slide-fade-leave-active {
    transition: all .4s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  }
  .slide-fade-enter, .slide-fade-leave-to
  /* .slide-fade-leave-active for below version 2.1.8 */ {
    transform: translateY(-10px);
    opacity: 0;
  }
  .staffCard .displayShow{
    display:inline-block;
    height:32px;
  }
  .staffCard .block{
    margin:15px 5px;
    line-height:32px;
  }    

</style>
<style>
    /*修改element-ui样式*/

  .staffCard .el-radio-button__inner:hover {
      color: #333;
  }
  .staffCard .el-radio-group .el-radio-button__inner:hover{
      background-color:#e7e7e7;
  }
  .staffCard .el-radio-group .el-radio-button__inner{
      background-color: #f4f4f4;
  }

  .staffCard .el-radio-group .is-active .el-radio-button__inner:hover{ 
        background-color: #d4d4d4 !important;
  }
  .staffCard .el-table th.gutter{
      display: none;
  }
  .staffCard .el-table th{
      white-space: nowrap;
      background-color: #fff;
      text-align: left;
  }
  .staffCard .el-table__header-wrapper thead div {
      background-color: #fff;
  }
  .staffCard .el-table__header-wrapper thead th>div.cell{
      padding-left: 0px;
      padding-right: 0px;
      text-align:center;
  }
  .staffCard .el-table__body-wrapper tr.el-table__row div.cell{
      padding-left: 0px;
      padding-right: 0px;
      text-align:center;
  }
  .staffCard .el-table{
    border:none;
  }
  .staffCard .el-table__body-wrapper table.el-table__body{
    width:100% !important;
    table-layout: auto;
  }
  .staffCard .el-table__header-wrapper .el-table__header{
    width:100% !important;
    table-layout: auto;
  }

  .staffCard .el-table .cell, .el-table th>div {
      padding-left: 0px;
      padding-right: 0px;
  }
  .staffCard .el-form--inline .el-form-item__label {
    width: 150px;
    float: none;
    display: inline-block;
  }
  .staffCard .el-pagination{
    display:inline-block;
  }
  .staffCard .el-table  tr td.width90, .staffCard .el-table  tr th.width90{
      min-width: 100px;
  }
  .staffCard .el-table  tr td.width40, .groupManage .el-table  tr th.width40{
      width: 40px;
  }
  .staffCard .el-table__empty-block{
    width:100% !important;
  }
</style>
